import 'package:flutter/material.dart';

class MyApp2 extends StatefulWidget {
  const MyApp2({super.key});

  @override
  State<MyApp2> createState() => _MyApp2State();
}

class _MyApp2State extends State<MyApp2> {
  // 状态变量(数据改变，视图更新)
  String name = '张三';
  int age = 20;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          '有状态组件',
          style: TextStyle(color: Colors.white, fontSize: 20),
        ),
        backgroundColor: Colors.orange,
        centerTitle: true,
      ),
      body: Center(child: Text('我的名字是$name,今年$age岁')),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            age = age + 1;
            print(age);
          });
        },
        child: Icon(Icons.add),
      ),
    );
  }
}
